package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.pojos.UpdateArticleInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author HNCheng
 * @version 1.0
 * @since 2023/8/3 16:44
 */
@Component
public class ArticleInfoHandleListener {
    @Autowired
    private ApArticleService apArticleService;
    @KafkaListener(topics = ArticleConstants.ARTICLE_SCORE_TOPIC)
    public void onMessage(String message){
        if(StringUtils.isNotBlank(message)){
            UpdateArticleInfo articleInfo = JSON.parseObject(message, UpdateArticleInfo.class);

            //更新文章详情
            apArticleService.updateArticleInfo(articleInfo);        }
    }
}
